#{extends 'CRUD/layout.html' /}
#{set title:messages.get('patients') /}

<script>
$(document).ready(function() {
	$("tbody tr").each(function() {
		$(this).removeClass("odd").removeClass("even");
		$(this).find("td").each(function() {
			var link = $(this).find('.hiddenLinks').text();
			$(this).click(function() {
				$(location).attr("href", link);
			});
			$(this).hover(
			  function () {
			    $(this).addClass("hover");
			  },
			  function () {
			    $(this).removeClass("hover");
			  });
		});	
	});
});
</script>

<div id="crudList" class="${type.name}">

    <h2 id="crudListTitle">&{'patients'}</h2>

    <div id="crudListSearch">
        #{crud.search /}
    </div>

    <div id="crudListTable">
        #{crud.table fields:['lastName', 'firstName', 'middleName', 'gender', 'birthday', 'medicineCard'] }
           #{crud.custom 'lastName'}
           		<span class="hiddenLinks">@{Patients.show(object.patientId)}</span>
                &{object.lastName}
		   #{/crud.custom}
		   #{crud.custom 'firstName'}
		        <span class="hiddenLinks">@{Patients.show(object.patientId)}</span>
                &{object.firstName}
		   #{/crud.custom}
		    #{crud.custom 'middleName'}
		        <span class="hiddenLinks">@{Patients.show(object.patientId)}</span>
                &{object.middleName}
		   #{/crud.custom}
		   #{crud.custom 'gender'}
		   		<span class="hiddenLinks">@{Patients.show(object.patientId)}</span>
				&{object.gender.name() == 'MALE' ? messages.get('gender.male'): messages.get('gender.female')}
           #{/crud.custom}
           #{crud.custom 'birthday'}
           	   <span class="hiddenLinks">@{Patients.show(object.patientId)}</span>
		       &{object.birthday.format()}
		   #{/crud.custom}
           #{crud.custom 'medicineCard'}
           	   <span class="hiddenLinks">@{MedicineCards.show(object.medicineCard.medicineCardId)}</span>
           	   &{'title.edit'}
		   #{/crud.custom}
		#{/crud.table}
    </div>

    <div id="crudListPagination">
        &{'total', models.Patient.count()}
        #{pagination /}
    </div>

    <p id="crudListAdd">
        <a href="@{blank()}">&{'patient.add'}</a>
    </p>

</div>
